#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    int removeElement_1(vector<int> &nums, int val)
    {
        auto it = nums.begin();
        while (it != nums.end()) {
            if (*it == val) {
                it = nums.erase(it);
            } else {
                ++it;
            }
        }
        return nums.size();
    }

    int removeElement_2(vector<int> &nums, int val)
    {
        int n = nums.size();
        int left = 0;
        for (int right = 0; right < n; ++right) {
            if (nums[right] != val) {
                nums[left] = nums[right];
                left++;
            }
        }
        return left;
    }

    int removeElement_3(vector<int> &nums, int val)
    {
        int left = 0, right = nums.size();
        while (left < right) {
            if (nums[left] == val) {
                nums[left] = nums[right - 1];
                right--;
            } else {
                left++;
            }
        }
        return left;
    }

    int removeElement_4(vector<int> &nums, int val)
    {
        auto iter = remove(nums.begin(), nums.end(), val);
        nums.erase(iter, nums.end());
        return nums.size();
    }
};

int main()
{
    vector<int> nums = {0, 1, 2, 2, 3, 0, 4, 2};
    int val = 2;
    Solution s;
    cout << s.removeElement_1(nums, val) << endl;
    return 0;
}
